# -*- coding: utf-8 -*-
# 文件读写

import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

try:
	f = open('E:\\python_study\\README.md','rb')
	print(f.read())
finally:
	if f:
		f.close()

# 简易写法
with open('E:\\python_study\\README.md','rb') as f:
	print(f.read())

with open('E:\\python_study\\README.md','rb') as f:
	for line in f.readlines():
		print(line.strip()) #把末尾的'\n'删掉

with open('E:\\python_study\\README.md','r',encoding='utf-8') as f:
	print(f.read())

# 忽略错误
with open('E:\\python_study\\README.md','r',encoding='utf-8',errors='ignore') as f:
	print(f.read())

# 写文件
with open('E:\\python_study\\README.md','a',encoding='utf-8',errors='ignore') as f:
	f.write('Hello,world!')

